﻿@* TypeVisibility: Internal *@
@model SlamCms.Web.Pager
@functions {
	IHtmlString PrintPageLink(int i) 
	{
		if (i == Model.PageNumber)
			return "<li>{0}</li>".F(i).ToHtml();
		else
			return "<li><a href=\"{0}\">{1}</a></li>".F(Model.ResolveUrl(i), i).ToHtml();
	}
}

@if (Model != null && Model.TotalPages > 1) { 
	<div class="paginator-list">
		<ul>
			@if (Model.HasPreviousPage()) { 
				<li><a href="@Model.ResolveUrl(Model.PreviousPage)">&lt;&lt;</a></li>
			}
		
			@PrintPageLink(1)
	
			@if (Model.PageNumber > 2) {
				if ( Model.TotalPages > 3 && Model.PageNumber > 3 ) {
					<li>...</li>
				}
				if (Model.PageNumber == Model.TotalPages && Model.TotalPages > 3) { 
					@PrintPageLink(Model.PageNumber - 2)
				}
				@PrintPageLink(Model.PageNumber - 1)
			} 

			@if (Model.PageNumber != 1 && Model.PageNumber != Model.TotalPages) { 
				@PrintPageLink(Model.PageNumber)
			}

			@if (Model.PageNumber < Model.TotalPages - 1) { 
				@PrintPageLink(Model.PageNumber + 1)
				if (Model.PageNumber == 1 && Model.TotalPages > 3) { 
					@PrintPageLink(Model.PageNumber + 2)
				}
				if (Model.TotalPages > 3 && Model.PageNumber < Model.TotalPages - 2) { 
					<li>...</li>
				}
			}

			@PrintPageLink(Model.TotalPages)

			@if (Model.HasNextPage()) { 
				<li><a href="@Model.ResolveUrl(Model.NextPage)">&gt;&gt;</a></li>
			}
		</ul>
	</div>
}